from langchain_core.prompts import PromptTemplate
from langchain_core.runnables import RunnableSequence
from langchain_openai import ChatOpenAI

# 定义模板
template = """Write a {adjective} poem about {subject}."""
prompt = PromptTemplate(template=template, input_variables=["adjective", "subject"])

# 创建语言模型实例
llm = ChatOpenAI(model="gpt-4o-mini", temperature=0)

# 使用 RunnableSequence 替代 LLMChain
# 这里我们创建一个序列，先应用 prompt 模板，然后将结果传递给 llm
sequence = RunnableSequence(prompt, llm)

# 执行序列并获取响应
response = sequence.invoke({"adjective": "sad", "subject": "ducks"})
print(response.content)
